/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package table;

import java.text.Format;
import javax.swing.table.DefaultTableCellRenderer;



/**
 *
 * @author Welisson
 */
public class TooltipCellRender extends DefaultTableCellRenderer{
    
    public TooltipCellRender() {  
            super();  
        }  
  
        public TooltipCellRender(Format f1, Format f2) {  
            super();  
            this.f1 = f1;  
            this.f2 = f2;  
        }  
  
        @Override  
        protected void setValue(Object value) {  
            String s;  
            if (value == null)  
                s = "";  
            else if (value instanceof Pair<?, ?>) {  
                @SuppressWarnings("unchecked")  
                Pair v = (Pair) value;  
                if (f1 == null)  
                    s = v.first.toString();  
                else  
                    s = f1.format(v.first);  
                if (f2 == null)  
                    setToolTipText(v.second.toString());  
                else  
                    setToolTipText(f2.format(v.second));  
            } else {  
                s = value.toString();  
            }  
            setText(s);  
        }  
  
        private Format f1;  
        private Format f2; 

}
